package main

import (
	"{{.projectName}}/route"
	"{{.projectName}}/variable"
	"{{.projectName}}/middleware"
	_ "{{.projectName}}/datasource"
	"github.com/savsgio/atreugo/v11"
)

func main() {
    if variable.DB != nil {
        db, _ := variable.DB.DB()
        defer db.Close()
    }

    variable.SERVER = atreugo.New(
        atreugo.Config{
            Addr: "0.0.0.0:1657",
        })

    m := middleware.NewMiddleware()
    variable.SERVER.UseBefore(m.Cors()){{- if eq .isUser true}}.UseBefore(m.JWTAuthMiddleware){{end}}

    route.New{{.structName}}Route().{{.structName}}RouteInit()

    if err := variable.SERVER.ListenAndServe(); err != nil {
        panic(err)
    }
}

